﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ExcelUtilities.Cfg
{
    /// <summary>
    /// 工作簿 配置信息
    /// </summary>
    public class Workbook
    {
        /// <summary>
        /// 名称
        /// </summary>
        [XmlAttribute]
        public string Name { get; set; }

        Bag<Worksheet> _worksheets = new Bag<Worksheet>();
        /// <summary>
        /// 工作簿包含的工作表配置信息集合
        /// </summary>
        [XmlElement("Worksheet")]
        public Bag<Worksheet> Worksheets
        {
            get { return _worksheets; }
            set { _worksheets = value; }
        }
        /// <summary>
        /// 查找 区域配置信息
        /// </summary>
        /// <param name="name">区域名</param>
        /// <returns>返回区域配置信息</returns>
        public Range FindRange(string name)
        {
            foreach (var ws in _worksheets)
            {
                Range range = ws.Ranges.FirstOrDefault(t => t.Name == name);
                if (range != null)
                    return range;
            }

            return null;
        }
    }
}
